package fr.afcepf.ai89.lagrandebouffe.data;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;

import fr.afcepf.ai89.lagrandebouffe.entity.Plat;

public class DataPlatImpl implements IDataPlat {
	private final String url =
			"jdbc:mysql://127.0.0.1:3306/lagrandebouffe";
	private final String login = "root";
	private final String mdp = "afcepf";
	private final String driver = "com.mysql.jdbc.Driver";
	private final String reqAjout =
			"INSERT INTO plat "
			+ "(libelle, description, prix, ingredients) "
			+ "VALUES (?,?,?,?)";
	@Override
	public Integer ajouter(Plat lePlat) {
		Connection cnx = null;
		try {
			Class.forName(driver);
			cnx = DriverManager.getConnection(url,login,mdp);
			PreparedStatement pstmt = cnx.prepareStatement(reqAjout);
			pstmt.setString(1, lePlat.getLibelle());
			pstmt.setString(2, lePlat.getDescription());
			pstmt.setFloat(3, lePlat.getPrix());
			pstmt.setString(4, lePlat.getIngredients());
			pstmt.executeUpdate();
			cnx.close();
		} catch (ClassNotFoundException | SQLException e) {
			e.printStackTrace();
		}
		// Voir apres ou pendant le cours de brigitte (JDBC;-)
		return null;
	}
	public static void main(String[] args) {
		Plat unPlat = new Plat(null, "un plat",
				"bon plat", 1_000_000.5F, "Que des bonnes choses");
		IDataPlat dataPlat = new DataPlatImpl();
		dataPlat.ajouter(unPlat);	
	}

	@Override
	public boolean manger(Plat lePlat) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public List<Plat> rechercher(String libelle) {
		// TODO Auto-generated method stub
		return null;
	}

}
